package com.rp.selfUser.swagger;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * 类说明: 配置Swagger2接口文档
 * 网址:  http://127.0.0.1/swagger-ui.html
 *
 * @author ****
 * @date 2019-08-28 10:16  新建
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    private static Boolean aBoolean;

    public static Boolean getABoolean() {
        return aBoolean;
    }

    @Value("${swagger.enable}")
    public void setABoolean(Boolean aBoolean) {
        SwaggerConfig.aBoolean = aBoolean;
    }

    public static ApiInfo apiInfo() {

        return new ApiInfoBuilder()
                .title("如朋接口文档")
                .description("cloudGroup | 仝世阳")
                // 作者信息
                .contact(new Contact("仝世阳", "1518143199@qq.com", "1518143199@qq.com"))
                .version("1.0.0")
                .build();
    }

    public static Docket createDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //序列化
                .directModelSubstitute(LocalDateTime.class, Date.class)
                .directModelSubstitute(LocalDate.class, String.class)
                .directModelSubstitute(LocalTime.class, String.class)
                .directModelSubstitute(ZonedDateTime.class, String.class)
                //配置是否启用Swagger，如果是false，在浏览器将无法访问
                .enable(aBoolean);
    }
}
